Stored Procedures [dbo].[asi_UserHasNetSecurity]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@contactMastervarchar(50)50
SQL Script
CREATE PROCEDURE [dbo].[asi_UserHasNetSecurity]
    @contactMaster varchar(50)
AS
    declare @userKey uniqueidentifier
    select @userKey = UserKey from UserMain where ContactMaster = @contactMaster
    if @@ROWCOUNT = 0
    begin
        select 0
        return
    end

    if exists (select * from UserRole where UserKey = @userKey and RoleKey <> (select RoleKey from RoleMain where Name = 'Everyone' and IsSystem = 1))
    begin
        select 1
        return
    end

    if exists (select * from GroupMember where MemberContactKey = @userKey)
    begin
        select 1
        return
    end

    if exists (
        select 1 from UserMain um left outer join AccessItem ai on um.UserKey = ai.UserKey
        where ai.AccessKey IS NOT NULL AND um.UserKey = @userKey
        GROUP BY um.UserId HAVING COUNT(um.UserId) > 1
    )
    begin
        select 1
        return
    end

    select 0

GO
Uses